module.exports = (app) => {
  const mongoose = app.mongoose;
  const Schema = mongoose.Schema;

  const SkuSchema = new Schema({
    skuName: {
      type: String,
      required: true,
    },
    skuDesc: {
      type: String,
      required: true,
    },
    weight: {
      type: String,
      required: true,
    },
    tmId: {
      type: Schema.Types.ObjectId,
      required: true,
    },
    category3Id: {
      type: Schema.Types.ObjectId,
      required: true,
    },
    skuImageList: [
      {
        type: Schema.Types.ObjectId,
        ref: "ImageList",
      },
    ],
    skuSaleAttrList: [
      {
        saleAttrId: Schema.Types.ObjectId,
        saleAttrName: String,
        saleAttrValueId: Schema.Types.ObjectId,
        saleAttrValueName: String,
      },
    ],
    skuAttrList: [
      {
        attrId: Schema.Types.ObjectId,
        attrName: String,
        attrValueId: Schema.Types.ObjectId,
        attrValueName: String,
      },
    ],
    spuId: {
      type: Schema.Types.ObjectId,
      required: true,
    },
    price: {
      type: Number,
      min: 0,
      required: true,
    },
    skuDefaultImg: {
      type: String,
      required: true,
    },
    // 默认上架
    isSale: {
      type: Number,
      enum: [0, 1],
      default: 1,
    },
    skuNum: {
      type: Number,
      required: true,
    },
    isAdmin: {
      type: Boolean,
      default: false,
    },
  });

  return mongoose.model("Sku", SkuSchema, "Sku");
};
